#include "StdAfx.h"
#include "DWaveblast.h"
#include <SFML/Graphics.hpp>
#include "../../DGlobals.h"

using namespace Postprocesses;

DWaveblast::DWaveblast(void)
{
}

DWaveblast::~DWaveblast(void)
{
}

void DWaveblast::update(float dt)
{
	static float fTimer = 0.0f;

	if(fTimer > m_fDuration)
	{
		fTimer = 0.0f;
		deactivate();
	}

	m_effect.lock()->SetParameter("origin", m_origin.x, m_origin.y);
	m_effect.lock()->SetParameter("time", fTimer);

	fTimer += dt;
}

void DWaveblast::startBlast(float duration, const vec2& originScreen)
{
	m_fDuration = duration;
	
	float sw = (float)DGlobals::instance().screenWidth();
	float sh = (float)DGlobals::instance().screenHeight();

	float ox = originScreen.x/sw;
	float oy = 1.0f - originScreen.y/sh;

	m_origin = vec2(ox, oy);

	m_effect.lock()->SetTexture("framebuffer", 0);

	activate();
}